package com.informatics.polymer.server.browserepository;

import org.restlet.Context;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.restlet.resource.InputRepresentation;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;

import com.informatics.polymer.server.Constants;
/**
 * Class is a restlet to  serve up the DataBaseDump.xml file to a listgrid.
 * @author ed
 * @version 1.0
 */
public class DatabaseResource extends Resource {
	public Representation represent(Variant variant) throws ResourceException {
		if (!MediaType.TEXT_XML.includes(variant.getMediaType())) {
			throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
		} else {
			String f = "/DataBaseDump"+".xml";
			String curDir = new String(System.getProperty("user.dir"));
			String databaseXML = curDir+f;
			return new InputRepresentation(getClass().getClassLoader()
					.getResourceAsStream(databaseXML),
					MediaType.TEXT_XML);
		}
	}
	public void init(Context context, Request request, Response response) {
		super.init(context, request, response);
		getVariants().add(Constants.XML_VARIANT);
	}

}
